/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FEMShapeFunctions;

import Integration.Gauss2D;
import Integration.IFunction2D;
import MathLib.triangulation.SaveStructures.Node;

/**
 *
 * @author mark
 */
public class FEMShapeFunction1ElementMatrixGenerator {
    protected Node A;
    protected Node B;
    protected Node C;

    protected double kx;
    protected double ky;

    protected FEMShapeFunction1 shapeFunc;


    public FEMShapeFunction1ElementMatrixGenerator() {

    }

    public FEMShapeFunction1ElementMatrixGenerator(Node A, Node B, Node C) {
        this.A = A;
        this.B = B;
        this.C = C;
    }

    public void update(){
        shapeFunc = new FEMShapeFunction1(A, B, C);
    }

    public Node getA() {
        return A;
    }

    public void setA(Node A) {
        this.A = A;
    }

    public Node getB() {
        return B;
    }

    public void setB(Node B) {
        this.B = B;
    }

    public Node getC() {
        return C;
    }

    public void setC(Node C) {
        this.C = C;
    }

    public double getKx() {
        return kx;
    }

    public void setKx(double kx) {
        this.kx = kx;
    }

    public double getKy() {
        return ky;
    }

    public void setKy(double ky) {
        this.ky = ky;
    }




    public double[][] GenerateKe(){
        double[][] tmp = new double[6][6];
        Gauss2D gau = new Gauss2D(20);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        SumFunctionShapeFunc1 tmpfunc = new SumFunctionShapeFunc1(shapeFunc, 0, 0, kx, ky);
        for (int i = 0; i < tmp.length; i++) {
            double[] ds = tmp[i];
            tmpfunc.setI(i+1);
            for (int j = 0; j < ds.length; j++) {
                tmpfunc.setJ(j+1);
                ds[j] = gau.gaussOnTriangle(tmpfunc, A, B, C);
            }
        }
        return tmp;
    }

    public double[][] GenerateMe(){
        double[][] tmp = new  double[6][6];
        Gauss2D gau = new Gauss2D(20);
        for(int i=0;i<6;i++){
            for(int j=0;j<6;j++){
                tmp[i][j] = gau.gaussOnTriangle(shapeFunc.calculateMultFuncs(i+1, j+1), A, B, C);
            }
        }
        return tmp;
    }

    public double[] GenerateF(final IFunction2D func){
        double[] res = new double[6];
        IFunction2D tmp = new IFunction2D() {

            public double calculate(double x, double y) {
                return func.calculate(x, y)*shapeFunc.calculate(x, y);
            }

            public double calculateDerivatyX(double x, double y) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public double calculateDerivatyY(double x, double y) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };
        Gauss2D gau = new Gauss2D(20);
        for (int i = 0; i < res.length; i++) {
            shapeFunc.setNodeNum(i+1);
            res[i] = gau.gaussOnTriangle(tmp, A, B, C);
        }

        return res;
    }
}
